var now = getNowFormatDateTime(); 
var username = sessionStorage.getItem("name");
var userid = sessionStorage.getItem("userId");
var jobnumber = sessionStorage.getItem("jobnumber");
var shopcode ="";
$(document).ready(function(){
	if(jobnumber ==0 || jobnumber == undefined || jobnumber == ""){
	     $('#shopcode')[0].style.display="none";
		 $('#shopcode1')[0].style.display="";
		 $('#search_img')[0].style.display="";
	}else{
		var jm = jobnumber.split(",");
		if(jm.length>0){
			for(var i=0;i<jm.length;i++){
				 $("#shopcode").append('<option value="'+jm[i]+'">'+jm[i]+'</option>');
			}
			setshopname($('#shopcode').val());
		}
		$("#shopcode").change(function(){
      		setshopname($('#shopcode').val());
   		});
	}
	$('#search_img').on('click',function(){
		if( $("#shopcode1").val() == ""  ||  $("#shopcode1").val() == undefined){
			alert("门店号不能为空")
		}else{
			setshopname($('#shopcode1').val());
		}
	});
	//search_time(2022);
	//getInfo();
});
function getInfo(time){
	$.ajax({
		url: '../../repair_info/getchart'
		,type:'post'
		,dataType:'json'
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"shopcode":shopcode,"date":time})  
		,success: function(res){
			console.log(res);
			var cdata = [''];
			var cdata1 = [''];
			var cdata2 = [''];
			for(var i=0;i<res.data.length;i++){
			  cdata.push(res.data[i].sum);
			  cdata1.push(res.data[i].cost);
			  cdata2.push(res.data[i].xvhao);
			}
			chart('pc','维修频次',cdata);
			cdata = ['',50, 200, 240, 340];
			chart('fy','维修费用',cdata1);
			cdata = ['',5, 2, 9, 3];
			chart('pm','维修排名',cdata2);
		}
	});
}
function search_time(time){
	$(".child2020")[0].style.backgroundColor="#599EF8";
	$(".child2021")[0].style.backgroundColor="#599EF8";
	$(".child2022")[0].style.backgroundColor="#599EF8";
	$(".child"+time)[0].style.backgroundColor="#BEBEBE";
	getInfo(time);
}
function chart(chartname,ytitle,cdata){
	  var myChart = echarts.init(document.getElementById(chartname));
      var option = {
		  xAxis: {
		    type: 'category',
		    boundaryGap: false,
		    data: ['月','1', '2', '3', '4', '5', '6', '7','8', '9', '10', '11', '12']
		  },
		  yAxis: {
			name: ytitle,
		  	type: 'value',
		  },
		  series: [
		    {
		      data: cdata,
		      type: 'line'
		    }
		  ]
		};
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
}
function setshopname(code){
    shopcode =code;
	$('#shopname').html("");
	$.ajax({
			url: '../../repair_info/fillshopname'
			,type:'post'
			,dataType:'json'
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({'shopcode':shopcode})  
			,success: function(res){
				console.log(res);
				if(res.data.field != undefined){
					$('#shopname').prepend(res.data.field.deptname);
				}
				search_time(2022);
			}
	});
}